﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Security.Principal;

namespace BackendServer.Security
{
    internal class CustomPrincipal : IPrincipal
    {
        private IIdentity _identity;
        private DateTime _created;
        private List<string> _roles = new List<string>();

        #region IPrincipal Members

        IIdentity IPrincipal.Identity
        {
            get { return _identity; }
        }

        bool IPrincipal.IsInRole(string role)
        {
            return _roles.Contains(role);
        }

        #endregion

        public CustomPrincipal(IIdentity identity, string[] roles)
        {
            _created = DateTime.Now;

            if (identity == null)
            {
                throw new ArgumentNullException("identity");
            }

            _identity = identity;

            if (roles != null)
                _roles.AddRange(roles);
        }
    }
}